﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace dbPoll_Application.Models
{
    public class DemographicQuestion : MultipleChoiceQuestion
    {
        public virtual DemographicQuestion compareWith { get; set; }
        public virtual ParticipantField linkedField { get; set; }

        public DemographicQuestion()
        {
            this.questionID = -1;
            this.question = String.Empty;
            this.creationTime = DateTime.Now;
            this.deletionTime = null;
            this.questionNumber = -1;
            this.type = QuestionType.Demographic;
            this.fontType = "Helvetica";
            this.fontColour = "#000000";
            this.fontSize = 30;
            this.feedback = null;
            this.resultsChart = null;
            this.comparisonChart = null;
            this.asynchronous = true;
            this.responded = null;
            this.countdownTimer = null;
            this.responseCounter = null;
            this.correctAnswerIndicator = null;
            this.responseGrid = null;
            this.allowedAnswers = 1;
            this.options = null;
            this.compareWith = null;
            this.linkedField = null;
        }

        public DemographicQuestion(int questionNumber)
        {
            this.questionID = -1;
            this.question = String.Empty;
            this.creationTime = DateTime.Now;
            this.deletionTime = null;
            this.questionNumber = questionNumber;
            this.type = QuestionType.Demographic;
            this.fontType = "Helvetica";
            this.fontColour = "#0000000";
            this.fontSize = 30;
            this.feedback = new HashSet<Feedback>();
            this.resultsChart = new QuestionChart("Vertical Bar", "Percentage", "green, orange, yellow, red", true);
            this.comparisonChart = new QuestionChart("Vertical Bar", "Percentage", "green, orange, yellow, red", false);
            this.asynchronous = true;
            this.responded = new HashSet<Participant>();
            this.countdownTimer = new CountdownTimer(false, 30);
            this.responseCounter = new ResponseCounter(false);
            this.correctAnswerIndicator = new CorrectAnswerIndicator(false);
            this.responseGrid = new ResponseGrid(false, "Name");
            this.allowedAnswers = 1;
            this.options = new List<QuestionOption>();
            this.compareWith = null;
            this.linkedField = null;
        }

        public DemographicQuestion(int questionNumber, String fontType, String fontColour, int fontSize, QuestionChart resultsChart, CountdownTimer countdownTimer, ResponseCounter responseCounter, CorrectAnswerIndicator correctAnswerIndicator, ResponseGrid responseGrid)
        {
            this.questionID = -1;
            this.question = String.Empty;
            this.creationTime = DateTime.Now;
            this.deletionTime = null;
            this.questionNumber = questionNumber;
            this.type = QuestionType.Demographic;
            this.fontType = fontType;
            this.fontColour = fontColour;
            this.fontSize = fontSize;
            this.feedback = new HashSet<Feedback>();
            this.resultsChart = new QuestionChart(resultsChart);
            this.comparisonChart = new QuestionChart(resultsChart);
            this.asynchronous = true;
            this.responded = new HashSet<Participant>();
            this.countdownTimer = new CountdownTimer(countdownTimer);
            this.responseCounter = new ResponseCounter(responseCounter);
            this.correctAnswerIndicator = new CorrectAnswerIndicator(correctAnswerIndicator);
            this.responseGrid = new ResponseGrid(responseGrid);
            this.allowedAnswers = 1;
            this.options = new List<QuestionOption>();
            this.compareWith = null;
            this.linkedField = null;
        }

        public DemographicQuestion(int questionNumber, QuestionChart resultsChart, QuestionChart comparisonChart, CountdownTimer countdownTimer, ResponseCounter responseCounter, CorrectAnswerIndicator correctAnswerIndicator, ResponseGrid responseGrid, DemographicQuestion compareWith, ParticipantField linkedField)
        {
            this.questionID = -1;
            this.question = compareWith.question;
            this.creationTime = DateTime.Now;
            this.deletionTime = null;
            this.questionNumber = questionNumber;
            this.type = QuestionType.Demographic;
            this.fontType = compareWith.fontType;
            this.fontColour = compareWith.fontColour;
            this.fontSize = compareWith.fontSize;
            this.resultsChart = resultsChart;
            this.comparisonChart = comparisonChart;
            this.asynchronous = true;
            this.responded = new HashSet<Participant>();
            this.countdownTimer = countdownTimer;
            this.responseCounter = responseCounter;
            this.correctAnswerIndicator = correctAnswerIndicator;
            this.responseGrid = responseGrid;
            this.allowedAnswers = compareWith.allowedAnswers;
            this.options = compareWith.options;
            this.compareWith = compareWith;
            this.linkedField = linkedField;
        }

        public override MultipleChoiceQuestion GetCompareWith()
        {
            return this.compareWith;
        }

        public override void NullCompareWith()
        {
            this.compareWith = null;
        }
    }
}
